package com.wxsong.authplatform.authweb.dao.authority;

import com.wxsong.authplatform.authweb.dao.BaseDao;
import com.wxsong.authplatform.authweb.model.authority.Authority;
import com.wxsong.authplatform.authweb.model.menu.Menu;
import com.wxsong.authplatform.authweb.model.users.Users;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class AuthorityDao extends BaseDao {

    public Authority getByName(String userName){
        return this.getSqlSession().selectOne("AuthorityMap.selectByName", userName);
    }

    public Authority getById(Long id){
        return this.getSqlSession().selectOne("AuthorityMap.selectById", id);
    }

    public List<Authority> list(int from, int pageSize, Map<String, Object> paramMap){
        paramMap.put("from", from);
        paramMap.put("size", pageSize);
        return this.getSqlSession().selectList("AuthorityMap.selectList", paramMap);
    }

    public Long count(Map<String, Object> paramMap){
        return this.getSqlSession().selectOne("AuthorityMap.selectCount", paramMap);
    }

    public int add(Authority users){
        return this.getSqlSession().insert("AuthorityMap.insertAuthority", users);
    }

    public int update(Map paramMap){
        return this.getSqlSession().insert("AuthorityMap.updateAuthority", paramMap);
    }

    public int delete(Long[] ids){
        return this.getSqlSession().delete("AuthorityMap.deleteAuthority", ids);
    }

    public List<Menu> hasMenus(Long[] ids) {
        return this.getSqlSession().selectList("MenuMap.selectHasMenus", ids);
    }

    public List<Menu> noMenus(Long[] ids) {
        return this.getSqlSession().selectList("MenuMap.selectNoMenus", ids);
    }
}
